#include "application.h"
#include "customer.h"
#include "drv_l2_touch_panel.h"
#include "drv_l2_usbh_uvc.h"
#include "State_photo_capture.h"
MSG_Q_ID		PeripheralTaskQ;
void			*peripheral_task_q_stack[PERIPHERAL_TASK_QUEUE_MAX];
static INT8U	peripheral_para[PERIPHERAL_TASK_QUEUE_MAX_MSG_LEN];
INT8U			screen_saver_enable = 0;
INT32U			battery_charge_icon_blink_cnt = 0;
INT32U			battery_low_blink_cnt = 0;
INT32U			display_insert_sdc_cnt = 0;
INT32U			motion_detect_peripheral_cnt = 0;
INT32U			G_sensor_power_on_time = 0;
INT32U 			live_topbar_timer = 0;
#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
extern INT8U	Record_Blue_Led_Flag;
#endif

#if C_AUTO_TEST_POWER_ON_OFF == CUSTOM_ON
INT32U			gPower_off_count = 0;
#endif

#if C_TOUCH_PANEL
INT32U			home_rec_mic_icon_cnt = (5<<5);
static TOUCH_PANEL_KEY_INFO_S tp_key_info = {0};
#endif

extern INT8U	back_debounce_cnt;
extern INT8U	PreviewIsStopped;
INT32U Time_cnt = 0;


#if ENABLE_REAR_SENSOR_FROM_HOST_UVC
extern OS_EVENT	*USBHUVCTaskQ;
#endif

INT8U gUSB_CAM_CONNECT = 0;
INT8U usbcam_debounce_cnt = 0;
extern INT8U gDetect_USBHUVC_Plug;
extern INT8U gUSB20_11_Connect;

void task_peripheral_handling_init(void)
{
	DBG_PRINT("%s ... \r\n", __func__);
	PeripheralTaskQ = msgQCreate(PERIPHERAL_TASK_QUEUE_MAX, PERIPHERAL_TASK_QUEUE_MAX, PERIPHERAL_TASK_QUEUE_MAX_MSG_LEN);
	ap_peripheral_init();
}

#if C_RTC_REBOOT
extern INT8U gPower_Off_Set_Alarm;
#endif
#if C_AUTO_TEST_POWER_ON_OFF == CUSTOM_ON
extern INT8U gSet_alarm_30sec;
#endif

#if GP_UI == Touch_UI
INT32U home_rec_mic_icon_status_get(void)
{
	return home_rec_mic_icon_cnt;
}
#endif

extern void ap_sensor_led_crl();
extern void ap_seting_state_tick();

extern INT8U power_on_finish;
extern INT8U g_usb_host_UVC_data_error_count;
extern INT32U	uvc_device_state;

//add
extern INT8U display_logo_done;
extern INT16U capture_show_file_cnt_start;
extern INT8U sensor_led_crl;
INT8U avoid_usb_repeat_reinit = 1;
extern INT8U usb_no_sensor_show_timer_start;

void task_peripheral_handling_entry(void *para)
{
	#if C_WATCHDOG
	static INT8U sw_reset = 0;
	#endif
	static INT8U first_in=5;
	INT32U	msg_id;
	INT32U	power_on_auto_record = 0;
	INT8U	usb_detect_start, back_polling_start = 0;
	INT8U	aeawb_start;
	INT8U	volume_show_time;
	INT32U	tick_current	= 0;
	INT32U	tick_last_32hz	= 0;
	INT32U	tick_last_4hz	= 0;
	INT32U	tick_last_10hz	= 0;
	INT32U	tick_last_1sec	= 0;
	INT32U	tick_last_2sec	= 0;
	INT8U      connect_status;
	INT32S err;
	
	#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
	INT32U	led_flicker_1sec = 0;
	#endif
	
	#if C_AUTO_TEST_POWER_ON_OFF
	INT32U	tick_last_5sec	= 0;
	#endif

	aeawb_start = 1;
	volume_show_time = 0;
	usb_detect_start = 0;

	task_peripheral_handling_init();

	DBG_PRINT("%s ... \r\n", __func__);

	while(1)
	{
		if(msgQReceive(PeripheralTaskQ, &msg_id, peripheral_para, PERIPHERAL_TASK_QUEUE_MAX_MSG_LEN) == STATUS_FAIL)
		{
			continue;
		}

		switch(msg_id)
		{

		#if C_TOUCH_PANEL
		case MSG_PERIPHERAL_ITEM_LOCATION_REGISTER:
			ap_peripheral_touch_key_register((void*)peripheral_para);
			break;
		case MSG_PERIPHERAL_HOME_REC_MIC_ICON_SHOW:
			home_rec_mic_icon_cnt = (1<<5);	// (5<<5);
			break;
		#endif

		case MSG_PERIPHERAL_TASK_KEY_REGISTER:
			ap_peripheral_key_register(peripheral_para[0]);
			break;

		case MSG_PERIPHERAL_TASK_USBD_DETECT_INIT:
		{
			usb_detect_start = 1;
		}
			break;

		case MSG_PERIPHERAL_TASK_BATTERY_CHARGE_ICON_BLINK_START:
			battery_charge_icon_blink_cnt = 0x002f;
			break;
		case MSG_PERIPHERAL_TASK_LIVE_TOPBAR_TIMER:
			if (peripheral_para[0] == LIVE_BROWSE_GENERAL_SHOW)
			{
				live_topbar_timer = 96;
			}
			else
			{
				live_topbar_timer = 64;
			}
			break;
		//add 
		case MSG_PERIPHERAL_SENSOR_LED_CRL:
			//ap_sensor_led_crl();
			break;
		/*
		case MSG_PERIPHERAL_TASK_CAPTURE_FILE_SHOW_START:
			DBG_PRINT("ddddd111\r\n");
			capture_show_file_cnt_start = 24; //750ms
			break;
		*/
		case MSG_PERIPHERAL_TASK_BATTERY_CHARGE_ICON_BLINK_STOP:
			battery_charge_icon_blink_cnt = 0;
			break;

		case MSG_PERIPHERAL_TASK_BATTERY_LOW_BLINK_START:
			battery_low_blink_cnt = 0x001f;
			battery_low_blink_cnt |= 0x0a00;
			break;

		case MSG_PERIPHERAL_TASK_BATTERY_LOW_BLINK_STOP:
			if(battery_low_blink_cnt)
			{
				battery_low_blink_cnt = 0;
			}

			break;

		case MSG_PERIPHERAL_TASK_DISPLAY_PLEASE_INSERT_SDC:
			display_insert_sdc_cnt = 0x006f;
			break;

		case MSG_PERIPHERAL_TASK_TIMER_VOLUME_ICON_SHOW:
			volume_show_time = peripheral_para[0] * 20;
			break;

		case MSG_PERIPHERAL_TASK_G_SENSOR_POWER_ON_START:
			G_sensor_power_on_time = 0x0300;
			break;

		case MSG_PERIPHERAL_TASK_POLL_32HZ:
			tick_current = OSTimeGet();


			if(tick_current - tick_last_10hz >= 10)
			{
				tick_last_10hz = tick_current;
				msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_POLL_10HZ, NULL, 0, MSG_PRI_NORMAL);
			}			
			//if(tick_current - tick_last_4hz >= 25)
			if((tick_current - tick_last_4hz >= 25) && display_logo_done)
			{
				tick_last_4hz = tick_current;
				//msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_POLL_4HZ, NULL, 0, MSG_PRI_NORMAL);
			}

			if(tick_current - tick_last_1sec >= 100)
			{
				tick_last_1sec = tick_current;
				msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_POLL_1SEC, NULL, 0, MSG_PRI_NORMAL);
			}

			if(tick_current - tick_last_2sec >= 200)
			{
				tick_last_2sec = tick_current;
				msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_POLL_2SEC, NULL, 0, MSG_PRI_NORMAL);
			}

			if(tick_current - tick_last_32hz <= 3)
			{
				break;
			}

			#if C_AUTO_TEST_POWER_ON_OFF
			if(tick_current - tick_last_5sec >= 500)	// 5sec
			{
				tick_last_5sec = tick_current;
				msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_POLL_5SEC, NULL, 0, MSG_PRI_NORMAL);
			}
			#endif
		
			ap_seting_state_tick();
			usb_no_sensor_show_timer();
			ap_peripheral_key_judge();
			ap_peripheral_ad_key_judge();
			ap_peripheral_config_store();
			drv_l1_sys_wdt_clear();

			#if CRAZY_KEY_TEST
			if(crazy_key_enable)
				ap_peripheral_crazy_key_test();
			#endif

			if(usb_detect_start == 1)
			{
				//ap_peripheral_adaptor_out_judge();
				//ap_peripheral_usbd_io_detection();
			}
			
			#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
			if(Record_Blue_Led_Flag)
			{	
				led_flicker_1sec++;
				if(32<=led_flicker_1sec && led_flicker_1sec <64)
				{
					gpio_write_io(MACHINE_STATUS_BLUE_LED, DATA_HIGH);
				}
				
				if(64<=led_flicker_1sec && led_flicker_1sec <92)
				{
					gpio_write_io(MACHINE_STATUS_BLUE_LED, DATA_LOW);
					led_flicker_1sec=0;
				}
			}
			else
			{
				led_flicker_1sec=0;
				gpio_write_io(MACHINE_STATUS_BLUE_LED, DATA_HIGH);
			}
			#endif

				//add
			if (capture_show_file_cnt_start)
			{
				--capture_show_file_cnt_start;
				if (0 == capture_show_file_cnt_start)
				{
					//ap_capture_file_name_clear();
					//msgQSend(ApQ, MSG_APQ_CLEAR_CAPTURE_FILE_NAME, NULL, 0, MSG_PRI_NORMAL);
				}
			}
			if (live_topbar_timer)
			{
				--live_topbar_timer;
				if (0 == live_topbar_timer)
				{
					if (ap_live_show_get() == LIVE_DISK_FULL_SHOW || ap_live_show_get() == LIVE_DISK_NO_PHOTOS_SHOW)
					{
						ap_live_show_set(LIVE_GENERAL_SHOW);
					}
					else if (ap_live_show_get() == LIVE_BROWSE_GENERAL_SHOW)
					{
						ap_live_show_set(LIVE_NO_SHOW);
						ap_live_browse_display_update_command();
					}
					else
					{
						ap_live_show_set(LIVE_NO_SHOW);
					}
				}
			}
			ap_TFT_backlight_tmr_check();

			if(battery_charge_icon_blink_cnt)
			{
				battery_charge_icon_blink_cnt--;
				if(!(battery_charge_icon_blink_cnt & 0xfff))
				{
					if(battery_charge_icon_blink_cnt & 0x8000)
					{
						battery_charge_icon_blink_cnt &= ~0x8000;
						ap_state_handling_icon_show_cmd(ICON_BATTERY_CHARGED, 0, 0);
					}
					else
					{
						battery_charge_icon_blink_cnt |= 0x8000;
						ap_state_handling_icon_clear_cmd(ICON_BATTERY_CHARGED, 0, 0);
					}

					ap_browse_display_update_command();
					battery_charge_icon_blink_cnt |= 0x002f;
				}
			}

			if(battery_low_blink_cnt)
			{
				battery_low_blink_cnt--;
				if(!(battery_low_blink_cnt & 0x00ff))
				{
					if(battery_low_blink_cnt & 0x0f00)
					{
						battery_low_blink_cnt -= 0x0100;
					}
					else
					{
						DBG_PRINT("Battery low Power off!\r\n");
						msgQSend(ApQ, MSG_APQ_POWER_KEY_ACTIVE, NULL, 0, MSG_PRI_URGENT);
						battery_low_blink_cnt = 0;
						break;
					}

					if(battery_low_blink_cnt & 0x8000)
					{
						battery_low_blink_cnt &= ~0x8000;
						ap_state_handling_str_draw1(STR_PROMPT, WARN_STR_COLOR);
						ap_state_handling_str_draw(STR_BATTERY_LOW, WARN_STR_COLOR);
					}
					else
					{
						battery_low_blink_cnt |= 0x8000;
						ap_state_handling_str_draw_exit1();
						ap_state_handling_str_draw_exit();
						
					}

					battery_low_blink_cnt |= 0x001f;
				}
			}

			if(display_insert_sdc_cnt)
			{
				display_insert_sdc_cnt--;
				if(!display_insert_sdc_cnt)
				{
					ap_state_handling_str_draw_exit();
					ap_state_handling_str_draw_exit1();
				}
			}

			#if C_TOUCH_PANEL
			if(home_rec_mic_icon_cnt)
			{
				home_rec_mic_icon_cnt--;
				if(home_rec_mic_icon_cnt == 0)
				{
					ap_state_handling_icon_clear_cmd(ICON_MIC_ON, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_MIC_OFF, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_REC_TOUCH, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_REC_STOP, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_HOME, 0, 0);
					ap_state_handling_icon_clear_cmd(IC0N_PRE_FILE, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_FAST_BACK, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_PLAY2, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_FAST_PLAY, 0, 0);
					ap_state_handling_icon_clear_cmd(ICON_NEXT_FILE, 0, 0);

				}
			}
			#endif

			if(G_sensor_power_on_time)
			{
				G_sensor_power_on_time--;

				//check SDC
				if(G_sensor_power_on_time < (0x300 - 0x80))
				{
					if(!ap_peripheral_get_usbd_io_status())
					{
						if(ap_state_handling_storage_id_get() != STORAGE_DEVICE)
						{
							DBG_PRINT("G sensor on NO SDC Power off!\r\n");
							msgQSend(ApQ, MSG_APQ_POWER_KEY_ACTIVE, NULL, 0, MSG_PRI_NORMAL);
							G_sensor_power_on_time = 0;
							break;
						}
					}
				}

				if(!G_sensor_power_on_time)
				{
					//check adptor
					if(!ap_peripheral_get_usbd_io_status())
					{
						DBG_PRINT("G sensor on time over Power off!\r\n");
						msgQSend(ApQ, MSG_APQ_POWER_KEY_ACTIVE, NULL, 0, MSG_PRI_NORMAL);
						break;
					}
					else
					{
						DBG_PRINT("G sensor on time over restart recording\r\n");
						msgQSend(ApQ, MSG_APQ_FUNCTION_KEY_ACTIVE, NULL, 0, MSG_PRI_NORMAL);
						msgQSend(ApQ, MSG_APQ_FUNCTION_KEY_ACTIVE, NULL, 0, MSG_PRI_NORMAL);
					}
				}
			}

			#if C_MOTION_DETECTION
			#if C_MOTION_DETECTION_NO_CNACEL
			if(!state_record_MD_freeze_status_get())
			#endif // #if C_MOTION_DETECTION_NO_CNACEL
			{
				if(motion_detect_peripheral_cnt)
				{
					motion_detect_peripheral_cnt--;
					if(!motion_detect_peripheral_cnt)
					{
						ap_peripheral_motion_detect_judge();
						motion_detect_peripheral_cnt = 2;
					}
				}
			}

			#endif // #if C_MOTION_DETECTION

			if(volume_show_time)
			{
				volume_show_time--;
				if(!volume_show_time)
				{
					msgQSend(ApQ, MSG_APQ_VOLUME_SHOW_END, NULL, 0, MSG_PRI_NORMAL);
				}
			}

			break;
		case MSG_PERIPHERAL_TASK_POLL_10HZ:
		//case MSG_PERIPHERAL_TASK_POLL_4HZ:
			//DBG_PRINT("[DEBUG]back_det(tick_P, tick_os)=(%3d, %d)\r\n", tick_current, OSTimeGet());
			/*if(back_polling_start)
			{
				if(ap_peripheral_back_detect() == STATUS_OK)
				{
					#if ENABLE_REAR_SENSOR_FROM_HOST_UVC
					if(power_on_auto_record && !ap_peripheral_get_host_io_status())
					{
						if(OS_NO_ERR == msgQSend(ApQ, MSG_APQ_POWER_ON_AUTO_RECORD, NULL, 0, MSG_PRI_NORMAL))
						{
							power_on_auto_record = 0;
						}
					}
					#else
					if(power_on_auto_record)
					{
						if(OS_NO_ERR == msgQSend(ApQ, MSG_APQ_POWER_ON_AUTO_RECORD, NULL, 0, MSG_PRI_NORMAL))
						{
							power_on_auto_record = 0;
						}
					}
					#endif
				}
			}*/
			
			if((gDetect_USBHUVC_Plug == 1) && (power_on_finish == 1))
			{
				if(gUSB20_11_Connect == 1)    // USB2.0
				{
					connect_status = drv_l1_usbh_ehci_detect_port();
					/*if(connect_status)
					{
					DBG_PRINT("2.0 det!!\r\n");
					}*/
				}
				else       // USB1.1
				{
					connect_status = drv_l1_usbh_ohci_detect_port();
					/*if(connect_status)
					{
					DBG_PRINT("1.1 det!!\r\n");
					}*/
				}

				///DBG_PRINT("-%d---%d\r\n",connect_status,gUSB_CAM_CONNECT);
				if(connect_status)
				{
					if(gUSB_CAM_CONNECT == 0)
					{
						usbcam_debounce_cnt++;
						if(usbcam_debounce_cnt > 2)
						{
							usbcam_debounce_cnt = 0;
							gUSB_CAM_CONNECT = 1;
							//ap_usb_sensor_state_set(1);
							OSQPost(USBHUVCTaskQ, (void *) MSG_USB_HOST_UVC_PLUG_IN);
							err = msgQSend(ApQ, MSG_APQ_BACK_SENSOR_PLUG_IN, NULL, 0, MSG_PRI_NORMAL);
							DBG_PRINT("send MSG_APQ_BACK_SENSOR_PLUG_IN %d\r\n",err);
						}
					}
					else
					{
						usbcam_debounce_cnt = 0;
					}
				}
				else
				{
					if(gUSB_CAM_CONNECT == 1)
					{
						usbcam_debounce_cnt++;
						if(usbcam_debounce_cnt > 2)
						{
							usbcam_debounce_cnt = 0;
							gUSB_CAM_CONNECT = 0;
							//ap_usb_sensor_state_set(0);
							OSQPost(USBHUVCTaskQ, (void *) MSG_USB_HOST_UVC_PLUG_OUT);
							msgQSend(ApQ, MSG_APQ_BACK_SENSOR_PLUG_OUT, NULL, 0, MSG_PRI_NORMAL);
						}
					}
					else
					{
						usbcam_debounce_cnt = 0;
					}
				}
			}
			if (first_in && (connect_status == 0) && (gUSB_CAM_CONNECT == 0))   
			{     		DBG_PRINT("first power no sensor signal\r\n");   
					//first_in = 0;    
					if (!(--first_in)){
						//DBG_PRINT("重新\r\n");   
						//USB20_or_USB11_flag2=1;
						//gUSB20_11_Connect = 1;//yjw  need
						//gApp_Select_Res=0;//when run USB2.0,REAR have two resolution,0: choose big one,1:720P,2:VGA.(default:0)
						//uvc_host_init();
						//OSTimeDly(10);
						//OSQPost(USBHUVCTaskQ, (void *) MSG_USB_HOST_UVC_PLUG_OUT);
						usb_no_sensor_show_timer_start = 1;
					msgQSend(ApQ, MSG_APQ_USB_DISCONNECT_SHOW, NULL, 0, MSG_PRI_NORMAL);    
					}
			}
			//if((uvc_device_state == UVC_DEV_STATE_GETTING_JPEG)&&(gUSB20_11_Connect == 1))     // USB2.0
			if((uvc_device_state == UVC_DEV_STATE_GETTING_JPEG)&&(gUSB20_11_Connect == 1) && avoid_usb_repeat_reinit)     // USB2.0
			{
			    g_usb_host_UVC_data_error_count += 1;
			    if(g_usb_host_UVC_data_error_count >= 10)
			    {
			        g_usb_host_UVC_data_error_count = 0;						    
				 DBG_PRINT("usbh error");
				 OSQPost(USBHUVCTaskQ, (void *)MSG_USB_HOST_UVC_REINITIAL);
			    }
			}
			break;

		case MSG_PERIPHERAL_TASK_POLL_1SEC:
			//DBG_PRINT("[DEBUG]gsensor_det(tick_P, tick_os)=(%3d, %d)\r\n", tick_current, OSTimeGet());
			if((usb_detect_start == 1) && (power_on_auto_record == 0))
			{
					//ap_peripheral_read_gsensor();
			}

					///g_usb_host_UVC_data_error = 1;
			break;

		case MSG_PERIPHERAL_TASK_POLL_2SEC:
			#if C_RTC_REBOOT
			msgQSend(StorageServiceQ, MSG_SET_ALARM, NULL, 0, MSG_PRI_NORMAL);
			#endif

			#if C_SENSOR_ERROR_DETECT
			if(front_sensor_err_handle_en)
			{
				if(!front_sensor_frm_cnt)
				{
					DBG_PRINT("[ERROR]front sensor stopped, do sw reset now...\r\n");

					#if C_WATCHDOG
					msgQSend(ApQ, MSG_APQ_SW_RESET, NULL, 0, MSG_PRI_URGENT);
					sw_reset = 1;
					#else
					msgQSend(ApQ, MSG_APQ_POWER_KEY_ACTIVE, NULL, 0, MSG_PRI_URGENT);
					#endif

					front_sensor_err_handle_en = 0;
				}

				front_sensor_frm_cnt = 0;
			}
			#endif

			#if C_WATCHDOG
			if(sw_reset)
			{
				OSTimeDly(3000);
				sw_reset = 0;
			}
			#endif
			break;

		#if C_AUTO_TEST_POWER_ON_OFF
		case MSG_PERIPHERAL_TASK_POLL_5SEC:
			gPower_off_count += 1;
			if(gPower_off_count >= 18)
			{
				gPower_off_count = 0;
				DBG_PRINT("Auto test power off\r\n");
				msgQSend(ApQ, MSG_APQ_POWER_KEY_ACTIVE, NULL, 0, MSG_PRI_NORMAL);
			}
			break;
		#endif

		case MSG_PERIPHERAL_BACK_POLLING_START:
			back_polling_start = 1;
			back_debounce_cnt = 0;
			gDetect_USBHUVC_Plug = 1;
			break;

		case MSG_PERIPHERAL_BACK_POLLING_STOP:
			back_polling_start = 0;
			back_debounce_cnt = 0;
			break;

		#if C_MOTION_DETECTION

		//case MSG_PERIPHERAL_TASK_MOTION_DETECT_JUDGE:
		//	ap_peripheral_motion_detect_judge();
		//	break;
		case MSG_PERIPHERAL_TASK_MOTION_DETECT_START:
			ap_peripheral_motion_detect_start();
			motion_detect_peripheral_cnt = 32;
			break;

		case MSG_PERIPHERAL_TASK_MOTION_DETECT_STOP:
			ap_peripheral_motion_detect_stop();
			motion_detect_peripheral_cnt = 0;
			break;

		case MSG_PERIPHERAL_TASK_MOTION_DETECT_DELAY:
			motion_detect_peripheral_cnt = 0xff;
			break;
		#endif // #if C_MOTION_DETECTION

		#if C_SCREEN_SAVER
		case MSG_PERIPHERAL_TASK_LCD_BACKLIGHT_SET:
			ap_peripheral_clr_screen_saver_timer();
			ap_peripheral_lcd_backlight_set(peripheral_para[0]);
			break;

		case MSG_PERIPHERAL_TASK_SCREEN_SAVER_ENABLE:
			screen_saver_enable = 1;
			break;
		#endif // C_SCREEN_SAVER

		case MSG_PERIPHERAL_USBD_EXIT:
			usbd_exit = 1;
			break;

		case MSG_PERIPHERAL_TASK_ISP_ISO_SET:
			#if (_SENSOR_CSI_FRONT == 0) && (C_REAR_ONLY == CUSTOM_OFF)
			drv_l2_cdsp_set_iso(peripheral_para[0]);
			#endif
			break;

		#if ENABLE_REAR_SENSOR_FROM_HOST_UVC
		case MSG_PERIPHERAL_BACK_SENSOR_ENUM_SUCCESSFUL:
#if (USBH_TYPE == USBH_OHCI_TYPE)
			OSQPost(USBHUVCTaskQ, (void *) MSG_USB_HOST_UVC_START_GET_DATA);
#endif
			msgQSend(ApQ, MSG_APQ_BACK_SENSOR_PLUG_IN, NULL, 0, MSG_PRI_NORMAL);

			if(power_on_auto_record)
			{
				while(OS_NO_ERR != msgQSend(ApQ, MSG_APQ_POWER_ON_AUTO_RECORD, NULL, 0, MSG_PRI_NORMAL))
				{
					DBG_PRINT("[WARN] Starting power on auto record fail @%s:%d\r\n", __func__, __LINE__);
					OSTimeDly(1);
				}
				power_on_auto_record = 0;
			}
			break;

		case MSG_PERIPHERAL_BACK_SENSOR_ENUM_FAILED:
			/* USB host enumerate device failed */
			if(power_on_auto_record)
			{
				while(OS_NO_ERR != msgQSend(ApQ, MSG_APQ_POWER_ON_AUTO_RECORD, NULL, 0, MSG_PRI_NORMAL))
				{
					DBG_PRINT("[WARN] Starting power on auto record fail @%s:%d\r\n", __func__, __LINE__);
					OSTimeDly(1);
				}
				power_on_auto_record = 0;
			}
			break;

		case MSG_PERIPHERAL_BACK_SENSOR_DEVICE_NOT_FOUND:
			/* USB host could not found device(port status failed) */
			break;

		case MSG_PERIPHERAL_BACK_SENSOR_REVERSE_PRAKING_DETECTED:
			/* USB host detected revse parking event */
			msgQSend(ApQ, MSG_APQ_BACK_A_CAR_ON, NULL, 0, MSG_PRI_NORMAL);
			back_a_car_status_set(1);
			//DBG_PRINT("MSG_PERIPHERAL_BACK_SENSOR_REVERSE_PRAKING_DETECTED\r\n");
			break;

		case MSG_PERIPHERAL_BACK_SENSOR_REVERSE_PRAKING_REMOVED:
			/* USB host removed revse parking event */
			msgQSend(ApQ, MSG_APQ_BACK_A_CAR_OFF, NULL, 0, MSG_PRI_NORMAL);
			back_a_car_status_set(0);
			//DBG_PRINT("MSG_PERIPHERAL_BACK_SENSOR_REVERSE_PRAKING_REMOVED\r\n");
			break;
		#endif // #if ENABLE_REAR_SENSOR_FROM_HOST_UVC

		#if C_TOUCH_PANEL
		case MSG_PERIPHERAL_TOUCH_PANEL_EVENT_REPORT:
			drv_l2_touch_panel_process_event(&tp_key_info);
			ap_peripheral_touch_panel_key_process(&tp_key_info);
			break;
		#endif

		default:
			break;
		}
	}
}
